home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / java / awt / Event.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  22.8 KB  |  805 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)Event.java    1.64 98/08/17
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14. package java.awt;
  15.  
  16. import java.awt.event.*;
  17. import java.io.*;
  18.  
  19. /**
  20.  * <code>Event</code> is a platform-independent class that
  21.  * encapsulates events from the platform's Graphical User
  22.  * Interface in the Java 1.0 event model. In Java 1.1
  23.  * and later versions, the <code>Event</code> class is maintained
  24.  * only for backwards compatibilty. The information in this
  25.  * class description is provided to assist programmers in
  26.  * converting Java 1.0 programs to the new event model.
  27.  * <p>
  28.  * In the Java 1.0 event model, an event contains an
  29.  * {@link Event#id} field
  30.  * that indicates what type of event it is and which other
  31.  * <code>Event</code> variables are relevant for the event.
  32.  * <p>
  33.  * For keyboard events, {@link Event#key}
  34.  * contains a value indicating which key was activated, and
  35.  * {@link Event#modifiers} contains the
  36.  * modifiers for that event.  For the KEY_PRESS and KEY_RELEASE
  37.  * event ids, the value of <code>key</code> is the unicode
  38.  * character code for the key. For KEY_ACTION and
  39.  * KEY_ACTION_RELEASE, the value of <code>key</code> is
  40.  * one of the defined action-key identifiers in the
  41.  * <code>Event</code> class (<code>PGUP</code>,
  42.  * <code>PGDN</code>, <code>F1</code>, <code>F2</code>, etc).
  43.  *
  44.  * @version 1.64 08/17/98
  45.  * @author     Sami Shaio
  46.  * @since      JDK1.0
  47.  */
  48. public class Event implements java.io.Serializable {
  49.     private transient long data;
  50.  
  51.     /* Modifier constants */
  52.  
  53.     /**
  54.      * This flag indicates that the Shift key was down when the event
  55.      * occurred.
  56.      */
  57.     public static final int SHIFT_MASK        = 1 << 0;
  58.  
  59.     /**
  60.      * This flag indicates that the Control key was down when the event
  61.      * occurred.
  62.      */
  63.     public static final int CTRL_MASK        = 1 << 1;
  64.  
  65.     /**
  66.      * This flag indicates that the Meta key was down when the event
  67.      * occurred. For mouse events, this flag indicates that the right
  68.      * button was pressed or released.
  69.      */
  70.     public static final int META_MASK        = 1 << 2;
  71.  
  72.     /**
  73.      * This flag indicates that the Alt key was down when
  74.      * the event occurred. For mouse events, this flag indicates that the
  75.      * middle mouse button was pressed or released.
  76.      */
  77.     public static final int ALT_MASK        = 1 << 3;
  78.  
  79.     /* Action keys */
  80.  
  81.     /**
  82.      * The Home key, a non-ASCII action key.
  83.      */
  84.     public static final int HOME        = 1000;
  85.  
  86.     /**
  87.      * The End key, a non-ASCII action key.
  88.      */
  89.     public static final int END            = 1001;
  90.  
  91.     /**
  92.      * The Page Up key, a non-ASCII action key.
  93.      */
  94.     public static final int PGUP        = 1002;
  95.  
  96.     /**
  97.      * The Page Down key, a non-ASCII action key.
  98.      */
  99.     public static final int PGDN        = 1003;
  100.  
  101.     /**
  102.      * The Up Arrow key, a non-ASCII action key.
  103.      */
  104.     public static final int UP            = 1004;
  105.  
  106.     /**
  107.      * The Down Arrow key, a non-ASCII action key.
  108.      */
  109.     public static final int DOWN        = 1005;
  110.  
  111.     /**
  112.      * The Left Arrow key, a non-ASCII action key.
  113.      */
  114.     public static final int LEFT        = 1006;
  115.  
  116.     /**
  117.      * The Right Arrow key, a non-ASCII action key.
  118.      */
  119.     public static final int RIGHT        = 1007;
  120.  
  121.     /**
  122.      * The F1 function key, a non-ASCII action key.
  123.      */
  124.     public static final int F1            = 1008;
  125.  
  126.     /**
  127.      * The F2 function key, a non-ASCII action key.
  128.      */
  129.     public static final int F2            = 1009;
  130.  
  131.     /**
  132.      * The F3 function key, a non-ASCII action key.
  133.      */
  134.     public static final int F3            = 1010;
  135.  
  136.     /**
  137.      * The F4 function key, a non-ASCII action key.
  138.      */
  139.     public static final int F4            = 1011;
  140.  
  141.     /**
  142.      * The F5 function key, a non-ASCII action key.
  143.      */
  144.     public static final int F5            = 1012;
  145.  
  146.     /**
  147.      * The F6 function key, a non-ASCII action key.
  148.      */
  149.     public static final int F6            = 1013;
  150.  
  151.     /**
  152.      * The F7 function key, a non-ASCII action key.
  153.      */
  154.     public static final int F7            = 1014;
  155.  
  156.     /**
  157.      * The F8 function key, a non-ASCII action key.
  158.      */
  159.     public static final int F8            = 1015;
  160.  
  161.     /**
  162.      * The F9 function key, a non-ASCII action key.
  163.      */
  164.     public static final int F9            = 1016;
  165.  
  166.     /**
  167.      * The F10 function key, a non-ASCII action key.
  168.      */
  169.     public static final int F10            = 1017;
  170.  
  171.     /**
  172.      * The F11 function key, a non-ASCII action key.
  173.      */
  174.     public static final int F11            = 1018;
  175.  
  176.     /**
  177.      * The F12 function key, a non-ASCII action key.
  178.      */
  179.     public static final int F12            = 1019;
  180.  
  181.     /**
  182.      * The Print Screen key, a non-ASCII action key.
  183.      */
  184.     public static final int PRINT_SCREEN    = 1020;
  185.  
  186.     /**
  187.      * The Scroll Lock key, a non-ASCII action key.
  188.      */
  189.     public static final int SCROLL_LOCK        = 1021;
  190.  
  191.     /**
  192.      * The Caps Lock key, a non-ASCII action key.
  193.      */
  194.     public static final int CAPS_LOCK        = 1022;
  195.  
  196.     /**
  197.      * The Num Lock key, a non-ASCII action key.
  198.      */
  199.     public static final int NUM_LOCK        = 1023;
  200.  
  201.     /**
  202.      * The Pause key, a non-ASCII action key.
  203.      */
  204.     public static final int PAUSE        = 1024;
  205.  
  206.     /**
  207.      * The Insert key, a non-ASCII action key.
  208.      */
  209.     public static final int INSERT        = 1025;
  210.  
  211.     /* Non-action keys */
  212.  
  213.     /**
  214.      * The Enter key.
  215.      */
  216.     public static final int ENTER        = '\n';
  217.  
  218.     /**
  219.      * The BackSpace key.
  220.      */
  221.     public static final int BACK_SPACE        = '\b';
  222.  
  223.     /**
  224.      * The Tab key.
  225.      */
  226.     public static final int TAB            = '\t';
  227.  
  228.     /**
  229.      * The Escape key.
  230.      */
  231.     public static final int ESCAPE        = 27;
  232.  
  233.     /**
  234.      * The Delete key.
  235.      */
  236.     public static final int DELETE        = 127;
  237.  
  238.  
  239.     /* Base for all window events. */
  240.     private static final int WINDOW_EVENT     = 200;
  241.  
  242.     /**
  243.      * The user has asked the window manager to kill the window.
  244.      */
  245.     public static final int WINDOW_DESTROY     = 1 + WINDOW_EVENT;
  246.  
  247.     /**
  248.      * The user has asked the window manager to expose the window.
  249.      */
  250.     public static final int WINDOW_EXPOSE     = 2 + WINDOW_EVENT;
  251.  
  252.     /**
  253.      * The user has asked the window manager to iconify the window.
  254.      */
  255.     public static final int WINDOW_ICONIFY    = 3 + WINDOW_EVENT;
  256.  
  257.     /**
  258.      * The user has asked the window manager to de-iconify the window.
  259.      */
  260.     public static final int WINDOW_DEICONIFY    = 4 + WINDOW_EVENT;
  261.  
  262.     /**
  263.      * The user has asked the window manager to move the window.
  264.      */
  265.     public static final int WINDOW_MOVED    = 5 + WINDOW_EVENT;
  266.  
  267.     /* Base for all keyboard events. */
  268.     private static final int KEY_EVENT         = 400;
  269.  
  270.     /**
  271.      * The user has pressed a normal key.
  272.      */
  273.     public static final int KEY_PRESS         = 1 + KEY_EVENT;
  274.  
  275.     /**
  276.      * The user has released a normal key.
  277.      */
  278.     public static final int KEY_RELEASE     = 2 + KEY_EVENT;
  279.  
  280.     /**
  281.      * The user has pressed a non-ASCII <em>action</em> key.
  282.      * The <code>key</code> field contains a value that indicates
  283.      * that the event occurred on one of the action keys, which
  284.      * comprise the 12 function keys, the arrow (cursor) keys,
  285.      * Page Up, Page Down, Home, End, Print Screen, Scroll Lock,
  286.      * Caps Lock, Num Lock, Pause, and Insert.
  287.      */
  288.     public static final int KEY_ACTION         = 3 + KEY_EVENT;
  289.  
  290.     /**
  291.      * The user has released a non-ASCII <em>action</em> key.
  292.      * The <code>key</code> field contains a value that indicates
  293.      * that the event occurred on one of the action keys, which
  294.      * comprise the 12 function keys, the arrow (cursor) keys,
  295.      * Page Up, Page Down, Home, End, Print Screen, Scroll Lock,
  296.      * Caps Lock, Num Lock, Pause, and Insert.
  297.      */
  298.     public static final int KEY_ACTION_RELEASE    = 4 + KEY_EVENT;
  299.  
  300.     /* Base for all mouse events. */
  301.     private static final int MOUSE_EVENT     = 500;
  302.  
  303.     /**
  304.      * The user has pressed the mouse button. The <code>ALT_MASK</code>
  305.      * flag indicates that the middle button has been pressed.
  306.      * The <code>META_MASK</code>flag indicates that the
  307.      * right button has been pressed.
  308.      * @see     java.awt.Event#ALT_MASK
  309.      * @see     java.awt.Event#META_MASK
  310.      */
  311.     public static final int MOUSE_DOWN         = 1 + MOUSE_EVENT;
  312.  
  313.     /**
  314.      * The user has released the mouse button. The <code>ALT_MASK</code>
  315.      * flag indicates that the middle button has been released.
  316.      * The <code>META_MASK</code>flag indicates that the
  317.      * right button has been released.
  318.      * @see     java.awt.Event#ALT_MASK
  319.      * @see     java.awt.Event#META_MASK
  320.      */
  321.     public static final int MOUSE_UP         = 2 + MOUSE_EVENT;
  322.  
  323.     /**
  324.      * The mouse has moved with no button pressed.
  325.      */
  326.     public static final int MOUSE_MOVE         = 3 + MOUSE_EVENT;
  327.  
  328.     /**
  329.      * The mouse has entered a component.
  330.      */
  331.     public static final int MOUSE_ENTER     = 4 + MOUSE_EVENT;
  332.  
  333.     /**
  334.      * The mouse has exited a component.
  335.      */
  336.     public static final int MOUSE_EXIT         = 5 + MOUSE_EVENT;
  337.  
  338.     /**
  339.      * The user has moved the mouse with a button pressed. The
  340.      * <code>ALT_MASK</code> flag indicates that the middle
  341.      * button is being pressed. The <code>META_MASK</code> flag indicates
  342.      * that the right button is being pressed.
  343.      * @see     java.awt.Event#ALT_MASK
  344.      * @see     java.awt.Event#META_MASK
  345.      */
  346.     public static final int MOUSE_DRAG         = 6 + MOUSE_EVENT;
  347.  
  348.  
  349.     /* Scrolling events */
  350.     private static final int SCROLL_EVENT     = 600;
  351.  
  352.     /**
  353.      * The user has activated the <em>line up</em>
  354.      * area of a scroll bar.
  355.      */
  356.     public static final int SCROLL_LINE_UP    = 1 + SCROLL_EVENT;
  357.  
  358.     /**
  359.      * The user has activated the <em>line down</em>
  360.      * area of a scroll bar.
  361.      */
  362.     public static final int SCROLL_LINE_DOWN    = 2 + SCROLL_EVENT;
  363.  
  364.     /**
  365.      * The user has activated the <em>page up</em>
  366.      * area of a scroll bar.
  367.      */
  368.     public static final int SCROLL_PAGE_UP    = 3 + SCROLL_EVENT;
  369.  
  370.     /**
  371.      * The user has activated the <em>page down</em>
  372.      * area of a scroll bar.
  373.      */
  374.     public static final int SCROLL_PAGE_DOWN    = 4 + SCROLL_EVENT;
  375.  
  376.     /**
  377.      * The user has moved the bubble (thumb) in a scroll bar,
  378.      * moving to an "absolute" position, rather than to
  379.      * an offset from the last postion.
  380.      */
  381.     public static final int SCROLL_ABSOLUTE    = 5 + SCROLL_EVENT;
  382.  
  383.     /**
  384.      * The scroll begin event.
  385.      */
  386.     public static final int SCROLL_BEGIN    = 6 + SCROLL_EVENT;
  387.  
  388.     /**
  389.      * The scroll end event.
  390.      */
  391.     public static final int SCROLL_END            = 7 + SCROLL_EVENT;
  392.  
  393.     /* List Events */
  394.     private static final int LIST_EVENT        = 700;
  395.  
  396.     /**
  397.      * An item in a list has been selected.
  398.      */
  399.     public static final int LIST_SELECT        = 1 + LIST_EVENT;
  400.  
  401.     /**
  402.      * An item in a list has been deselected.
  403.      */
  404.     public static final int LIST_DESELECT    = 2 + LIST_EVENT;
  405.  
  406.     /* Misc Event */
  407.     private static final int MISC_EVENT        = 1000;
  408.  
  409.     /**
  410.      * This event indicates that the user wants some action to occur.
  411.      */
  412.     public static final int ACTION_EVENT    = 1 + MISC_EVENT;
  413.  
  414.     /**
  415.      * A file loading event.
  416.      */
  417.     public static final int LOAD_FILE        = 2 + MISC_EVENT;
  418.  
  419.     /**
  420.      * A file saving event.
  421.      */
  422.     public static final int SAVE_FILE        = 3 + MISC_EVENT;
  423.  
  424.     /**
  425.      * A component gained the focus.
  426.      */
  427.     public static final int GOT_FOCUS        = 4 + MISC_EVENT;
  428.  
  429.     /**
  430.      * A component lost the focus.
  431.      */
  432.     public static final int LOST_FOCUS        = 5 + MISC_EVENT;
  433.  
  434.     /**
  435.      * The target component. This indicates the component over which the
  436.      * event occurred or with which the event is associated.
  437.      * This object has been replaced by AWTEvent.getSource()
  438.      *
  439.      * @serial
  440.      * @see java.awt.AWTEvent#getSource()
  441.      */
  442.     public Object target;
  443.  
  444.     /**
  445.      * The time stamp.
  446.      * Replaced by InputEvent.getWhen().
  447.      *
  448.      * @serial
  449.      * @see java.awt.InputEvent#getWhen()
  450.      */
  451.     public long when;
  452.  
  453.     /**
  454.      * Indicates which type of event the event is, and which
  455.      * other <code>Event</code> variables are relevant for the event.
  456.      * This has been replaced by AWTEvent.getID()
  457.      *
  458.      * @serial
  459.      * @see java.awt.AWTEvent.getID()
  460.      */
  461.     public int id;
  462.  
  463.     /**
  464.      * The <i>x</i> coordinate of the event.
  465.      * Replaced by MouseEvent.getX()
  466.      *
  467.      * @serial
  468.      * @see java.awt.MouseEvent#getX()
  469.      */
  470.     public int x;
  471.  
  472.     /**
  473.      * The <i>y</i> coordinate of the event.
  474.      * Replaced by MouseEvent.getY()
  475.      *
  476.      * @serial
  477.      * @see java.awt.MouseEvent#getY()
  478.      */
  479.     public int y;
  480.  
  481.     /**
  482.      * The key code of the key that was pressed in a keyboard event.
  483.      * This has been replaced by KeyEvent.getKeyCode()
  484.      *
  485.      * @serial
  486.      * @see java.awt.KeyEvent#getKeyCode()
  487.      */
  488.     public int key;
  489.  
  490.     /**
  491.      * The key character that was pressed in a keyboard event.
  492.      */
  493. //    public char keyChar;
  494.  
  495.     /**
  496.      * The state of the modifier keys.
  497.      * This is replaced with InputEvent.getModifiers()
  498.      * In java 1.1 MouseEvent and KeyEvent are subclasses
  499.      * of InputEvent.
  500.      *
  501.      * @serial
  502.      * @see java.awt.InputEvent#getModifiers()
  503.      */
  504.     public int modifiers;
  505.  
  506.     /**
  507.      * For <code>MOUSE_DOWN</code> events, this field indicates the
  508.      * number of consecutive clicks. For other events, its value is
  509.      * <code>0</code>.
  510.      * This field has been replaced by MouseEvent.getClickCount().
  511.      *
  512.      * @serial
  513.      * @see java.awt.MouseEvent.getClickCount().
  514.      */
  515.     public int clickCount;
  516.  
  517.     /**
  518.      * An arbitrary argument of the event. The value of this field
  519.      * depends on the type of event.
  520.      * <code>arg</code> has been replaced b event specific property.
  521.      *
  522.      * @serial
  523.      */
  524.     public Object arg;
  525.  
  526.     /**
  527.      * The next event. This field is set when putting events into a
  528.      * linked list.
  529.      * This has been replaced by EventQueue.
  530.      *
  531.      * @serial
  532.      * @see java.awt.EventQueue
  533.      */
  534.     public Event evt;
  535.  
  536.     /* table for mapping old Event action keys to KeyEvent virtual keys. */
  537.     private static final int actionKeyCodes[][] = {
  538.     /*    virtual key              action key   */
  539.         { KeyEvent.VK_HOME,        Event.HOME         },
  540.         { KeyEvent.VK_END,         Event.END          },
  541.         { KeyEvent.VK_PAGE_UP,     Event.PGUP         },
  542.         { KeyEvent.VK_PAGE_DOWN,   Event.PGDN         },
  543.         { KeyEvent.VK_UP,          Event.UP           },
  544.         { KeyEvent.VK_DOWN,        Event.DOWN         },
  545.         { KeyEvent.VK_LEFT,        Event.LEFT         },
  546.         { KeyEvent.VK_RIGHT,       Event.RIGHT        },
  547.         { KeyEvent.VK_F1,          Event.F1           },
  548.         { KeyEvent.VK_F2,          Event.F2           },
  549.         { KeyEvent.VK_F3,          Event.F3           },
  550.         { KeyEvent.VK_F4,          Event.F4           },
  551.         { KeyEvent.VK_F5,          Event.F5           },
  552.         { KeyEvent.VK_F6,          Event.F6           },
  553.         { KeyEvent.VK_F7,          Event.F7           },
  554.         { KeyEvent.VK_F8,          Event.F8           },
  555.         { KeyEvent.VK_F9,          Event.F9           },
  556.         { KeyEvent.VK_F10,         Event.F10          },
  557.         { KeyEvent.VK_F11,         Event.F11          },
  558.         { KeyEvent.VK_F12,         Event.F12          },
  559.         { KeyEvent.VK_PRINTSCREEN, Event.PRINT_SCREEN },
  560.         { KeyEvent.VK_SCROLL_LOCK, Event.SCROLL_LOCK  },
  561.         { KeyEvent.VK_CAPS_LOCK,   Event.CAPS_LOCK    },
  562.         { KeyEvent.VK_NUM_LOCK,    Event.NUM_LOCK     },
  563.         { KeyEvent.VK_PAUSE,       Event.PAUSE        },
  564.         { KeyEvent.VK_INSERT,      Event.INSERT       }
  565.     };
  566.  
  567.     /**
  568.      * This field controls whether or not the event is sent back
  569.      * down to the peer once the target has processed it -
  570.      * false means it's sent to the peer, true means it's not.
  571.      *
  572.      * @serial
  573.      * @see isConsumed()
  574.      */
  575.     private boolean consumed = false;
  576.  
  577.     /*
  578.      * JDK 1.1 serialVersionUID
  579.      */
  580.     private static final long serialVersionUID = 5488922509400504703L;
  581.  
  582.     static {
  583.         /* ensure that the necessary native libraries are loaded */
  584.     Toolkit.loadLibraries();
  585.     initIDs();
  586.     }
  587.  
  588.     /**
  589.      * Initialize JNI field and method IDs for fields that may be
  590.        accessed from C.
  591.      */
  592.     private static native void initIDs();
  593.  
  594.     /**
  595.      * Creates an instance of <code>Event</code> with the specified target
  596.      * component, time stamp, event type, <i>x</i> and <i>y</i>
  597.      * coordinates, keyboard key, state of the modifier keys, and
  598.      * argument.
  599.      * @param     target     the target component.
  600.      * @param     when       the time stamp.
  601.      * @param     id         the event type.
  602.      * @param     x          the <i>x</i> coordinate.
  603.      * @param     y          the <i>y</i> coordinate.
  604.      * @param     key        the key pressed in a keyboard event.
  605.      * @param     modifiers  the state of the modifier keys.
  606.      * @param     arg        the specified argument.
  607.      */
  608.     public Event(Object target, long when, int id, int x, int y, int key,
  609.          int modifiers, Object arg) {
  610.     this.target = target;
  611.     this.when = when;
  612.     this.id = id;
  613.     this.x = x;
  614.     this.y = y;
  615.     this.key = key;
  616.     this.modifiers = modifiers;
  617.     this.arg = arg;
  618.     this.data = 0;
  619.     this.clickCount = 0;
  620.         switch(id) {
  621.           case ACTION_EVENT:
  622.           case WINDOW_DESTROY:
  623.           case WINDOW_ICONIFY:
  624.           case WINDOW_DEICONIFY:
  625.           case WINDOW_MOVED:
  626.           case SCROLL_LINE_UP:
  627.           case SCROLL_LINE_DOWN:
  628.           case SCROLL_PAGE_UP:
  629.           case SCROLL_PAGE_DOWN:
  630.           case SCROLL_ABSOLUTE:
  631.           case SCROLL_BEGIN:
  632.           case SCROLL_END:
  633.           case LIST_SELECT:
  634.           case LIST_DESELECT:
  635.             consumed = true; // these types are not passed back to peer
  636.             break;
  637.           default:
  638.         }
  639.     }
  640.  
  641.     /**
  642.      * Creates an instance of <code>Event</code>, with the specified target
  643.      * component, time stamp, event type, <i>x</i> and <i>y</i>
  644.      * coordinates, keyboard key, state of the modifier keys, and an
  645.      * argument set to <code>null</code>.
  646.      * @param     target     the target component.
  647.      * @param     when       the time stamp.
  648.      * @param     id         the event type.
  649.      * @param     x          the <i>x</i> coordinate.
  650.      * @param     y          the <i>y</i> coordinate.
  651.      * @param     key        the key pressed in a keyboard event.
  652.      * @param     modifiers  the state of the modifier keys.
  653.      */
  654.     public Event(Object target, long when, int id, int x, int y, int key, int modifiers) {
  655.     this(target, when, id, x, y, key, modifiers, null);
  656.     }
  657.  
  658.     /**
  659.      * Creates an instance of <code>Event</code> with the specified
  660.      * target component, event type, and argument.
  661.      * @param     target     the target component.
  662.      * @param     id         the event type.
  663.      * @param     arg        the specified argument.
  664.      */
  665.     public Event(Object target, int id, Object arg) {
  666.     this(target, 0, id, 0, 0, 0, 0, arg);
  667.     }
  668.  
  669.     /**
  670.      * Translates this event so that its <i>x</i> and <i>y</i>
  671.      * coordinates are increased by <i>dx</i> and <i>dy</i>,
  672.      * respectively.
  673.      * <p>
  674.      * This method translates an event relative to the given component.
  675.      * This involves, at a minimum, translating the coordinates into the
  676.      * local coordinate system of the given component. It may also involve
  677.      * translating a region in the case of an expose event.
  678.      * @param     dx     the distance to translate the <i>x</i> coordinate.
  679.      * @param     dy     the distance to translate the <i>y</i> coordinate.
  680.      */
  681.     public void translate(int x, int y) {
  682.     this.x += x;
  683.     this.y += y;
  684.     }
  685.  
  686.     /**
  687.      * Checks if the Shift key is down.
  688.      * @return    <code>true</code> if the key is down;
  689.      *            <code>false</code> otherwise.
  690.      * @see       java.awt.Event#modifiers
  691.      * @see       java.awt.Event#controlDown
  692.      * @see       java.awt.Event#metaDown
  693.      */
  694.     public boolean shiftDown() {
  695.     return (modifiers & SHIFT_MASK) != 0;
  696.     }
  697.  
  698.     /**
  699.      * Checks if the Control key is down.
  700.      * @return    <code>true</code> if the key is down;
  701.      *            <code>false</code> otherwise.
  702.      * @see       java.awt.Event#modifiers
  703.      * @see       java.awt.Event#shiftDown
  704.      * @see       java.awt.Event#metaDown
  705.      */
  706.     public boolean controlDown() {
  707.     return (modifiers & CTRL_MASK) != 0;
  708.     }
  709.  
  710.     /**
  711.      * Checks if the Meta key is down.
  712.      * @return    <code>true</code> if the key is down;
  713.      *            <code>false</code> otherwise.
  714.      * @see       java.awt.Event#modifiers
  715.      * @see       java.awt.Event#shiftDown
  716.      * @see       java.awt.Event#controlDown
  717.      */
  718.     public boolean metaDown() {
  719.     return (modifiers & META_MASK) != 0;
  720.     }
  721.  
  722.     void consume() {
  723.         switch(id) {
  724.           case KEY_PRESS:
  725.           case KEY_RELEASE:
  726.           case KEY_ACTION:
  727.           case KEY_ACTION_RELEASE:
  728.               consumed = true;
  729.               break;
  730.           default:
  731.               // event type cannot be consumed
  732.         }
  733.     }
  734.  
  735.     boolean isConsumed() {
  736.         return consumed;
  737.     }
  738.  
  739.     /*
  740.      * Returns the integer key-code associated with the key in this event,
  741.      * as described in java.awt.Event.
  742.      */
  743.     static int getOldEventKey(KeyEvent e) {
  744.         int keyCode = e.getKeyCode();
  745.         for (int i = 0; i < actionKeyCodes.length; i++) {
  746.             if (actionKeyCodes[i][0] == keyCode) {
  747.                 return actionKeyCodes[i][1];
  748.             }
  749.         }
  750.         return (int)e.getKeyChar();
  751.     }
  752.  
  753.     /*
  754.      * Returns a new KeyEvent char which corresponds to the int key
  755.      * of this old event.
  756.      */
  757.     char getKeyEventChar() {
  758.        for (int i = 0; i < actionKeyCodes.length; i++) {
  759.             if (actionKeyCodes[i][1] == key) {
  760.                 return KeyEvent.CHAR_UNDEFINED;
  761.             }
  762.        }
  763.        return (char)key;
  764.     }
  765.  
  766.     /**
  767.      * Returns the parameter string representing this event.
  768.      * This string is useful for debugging.
  769.      * @return    the parameter string of this event.
  770.      */
  771.     protected String paramString() {
  772.     String str = "id=" + id + ",x=" + x + ",y=" + y;
  773.     if (key != 0) {
  774.         str += ",key=" + key;
  775.     }
  776.     if (shiftDown()) {
  777.         str += ",shift";
  778.     }
  779.     if (controlDown()) {
  780.         str += ",control";
  781.     }
  782.     if (metaDown()) {
  783.         str += ",meta";
  784.     }
  785.     if (target != null) {
  786.         str += ",target=" + target;
  787.     }
  788.     if (arg != null) {
  789.         str += ",arg=" + arg;
  790.     }
  791.     return str;
  792.     }
  793.  
  794.     /**
  795.      * Returns a representation of this event's values as a string.
  796.      * @return    a string that represents the event and the values
  797.      *                 of its member fields.
  798.      * @see       java.awt.Event#paramString
  799.      * @since     JDK1.1
  800.      */
  801.     public String toString() {
  802.     return getClass().getName() + "[" + paramString() + "]";
  803.     }
  804. }
  805.